<template>
	<view class="wrap">
		<u-form :model="model" :rules="rules" ref="uForm">
			<u-form-item label-width="350" :label-position="labelPosition" label="泵压 (Pa)" prop="by">
				<u-input :border="border" placeholder="泵压 " v-model="model.by" type="digit"></u-input>
			</u-form-item>
			<u-form-item label-width="350" :label-position="labelPosition" label="内半径 (m)" prop="nj">
				<u-input :border="border" placeholder="内半径" v-model="model.nj" type="digit"></u-input>
			</u-form-item>
			<u-form-item label-width="350" :label-position="labelPosition" label="外半径 (m)" prop="wj">
				<u-input :border="border" placeholder="外半径" v-model="model.wj" type="digit"></u-input>
			</u-form-item>
		</u-form>

		<u-button type="primary" @click="submit">计算</u-button>

		<view class="u-config-wrap">
			<view class="u-config-item">
				<view class="u-item-title">计算结果</view>
			
				<view>
					剪切强度的值为：<span v-if="model.force"> {{model.force}} kN </span> Pa
				</view>
			</view>
			<view class="u-config-item">
				<view class="u-item-title">计算公式</view>
				<view class="u-item-desc">τ=Q/F=D^2P/2d^2</view>
				<view class="u-item-desc">其中 F=2×πd^2/4 ; Q=πD^2P/4</view>
				<view class="u-item-desc">
					式中：<br>
					Τ—钢材的抗剪强度，Pa；<br>
					P—泵压，Pa；<br>
					F—横截面积，m2；<br>
					Q—单位长度的重力，N。<br>
					D—外半径,m<br>
					d—内直径,m。<br>

				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				model: {
					by: '',
					nj: '',
					wj: '',
					force: ''
				},
				rules: {
					by: [{
						required: true,
						message: '请输入泵压',
						trigger: 'blur'
					}],
					nj: [{
						required: true,
						message: '请输入内半径',
						trigger: 'blur'
					}],
					wj: [{
						required: true,
						message: '请输入外半径',
						trigger: 'blur'
					}]
				},
				labelPosition: 'left',
				border: true,

			};
		},
		onReady() {
			this.$refs.uForm.setRules(this.rules);
		},
		methods: {
			submit() {
				this.$refs.uForm.validate(valid => {
					if (valid) {
						// σ=P/F
						const P = parseFloat(this.model.by);
						const D = parseFloat(this.model.wj);
						const d = parseFloat(this.model.nj);
						
						this.model.force = (0.5*Math.pow(D,2)*P/Math.pow(d,2)).toFixed(2);
					}
				});
			}
		}
	};
</script>

<style scoped lang="scss">
	.wrap {
		padding: 30rpx;
	}

	.u-config-wrap {
		margin-top: 30rpx;
	}

	.u-config-title {
		padding: 20rpx;
		font-size: 32rpx;
		font-weight: bold;
	}

	.u-config-item {
		padding: 20rpx;
	}

	.u-item-title {
		font-size: 28rpx;
		font-weight: bold;
		margin-bottom: 10rpx;
	}

	.u-item-desc {
		font-size: 24rpx;
		color: #666;
	}
</style>